//#include "server.h"
//#include "../mn.h"
//#include "../start_sym.h"
#include "gej_consts.h"
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <iostream>
#include <signal.h>
#include <sys/dir.h>
#include "../help.h"
#include "h_init.h"
using namespace std;

typedef set <string> SS;
typedef map <string, int> MSI;
SS e_cmds;
MSI e_m_cmds;

#define tr(container, iterator) \
        for(typeof(container.begin()) iterator=container.begin(); \
        it != container.end(); it++)
void init(string ejrund, string ejcond, SS &a, MSI &b)
{
    tr(a, it)
    {
        e_cmds.insert(*it);
    }
    tr(b, it)
    {
        pair <string, int >  a = *it;
        e_m_cmds[a.first] = a.second;
    }
    e_init_cmd(e_cmds, e_m_cmds);
}
extern void mg_ejudge(string &ejrund, string &ejcondir, set<string>& cmds, map <string, int>& mcmds)
{
    char* curdir;
    char symbol = '#';
    unsigned long long i = 100;
    /*while (getcwd(curdir, i) != 0)
        i++;*/
    chdir(ejrund.c_str());
    init(ejrund, ejcondir, cmds, mcmds);
    #define DEBUG
    #ifdef DEBUG
        cerr << "connected" << endl;
    #endif
    const int ge_ghelp = 3;
    const int ge_gexit = 2;
    bool Exit = false;
    do
    {
        string command;
        cout << symbol;
        cin >> command;
        switch (e_m_cmds[command])
        {
        case ge_gstop:
            void(); break;
        case ge_gstart:
            void(); break;
        case ge_grestart:
            void(); break;
        case ge_select:
            void(); break;
        case ge_create:
            void(); break;
        case ge_ghelp:
            print_help(e_cmds); break;
        case ge_gexit:
            Exit = true; break;
        }
    }
    while (!Exit);
    chdir(curdir);
}
